package net.aiion.weave.impl.feeding;

import net.aiion.weave.spi.feeding.Feed;
import net.aiion.weave.spi.feeding.FeedFactory;
import net.aiion.weave.spi.injection.annotations.Inject;
import net.aiion.weave.spi.messaging.MessageCallback;
import net.aiion.weave.spi.messaging.MessageQueue;
import net.aiion.weave.spi.messaging.annotations.Queue;
import net.aiion.weave.spi.naming.annotations.Named;
import net.aiion.weave.spi.naming.annotations.NotScoped;


@NotScoped
@Named
public class FeedFactoryImpl implements FeedFactory
{
    @Inject
    @Queue("org.weaveframework.feeding")
    private MessageQueue messageQueue;

    public FeedFactoryImpl() {
    }

    @Override
    public Feed createFeed(final String aName, final String aValue) {
        return new FeedImpl(aName, aValue);
    }

    @Override
    public void dispatchFeed(final String aName, final String aValue) {
        dispatchFeed(aName, aValue, null);
    }

    @Override
    public void dispatchFeed(final String aName, final String aValue, final MessageCallback aMessageCallback) {
        dispatchFeed(createFeed(aName, aValue), aMessageCallback);
    }

    @Override
    public void dispatchFeed(final Feed aFeed) {
        dispatchFeed(aFeed, null);
    }

    @Override
    public void dispatchFeed(final Feed aFeed, final MessageCallback aMessageCallback) {
        messageQueue.sendMessage(new FeedMessageImpl(aFeed), aMessageCallback);
    }
}
